{% extends 'base_with_listing.html' %}

{% load go_back_link %}

{% block title %}User list{% endblock %}

{% block header %}Find user{% endblock %}

{% block before_table %}
    <div class="user_search">
      <center>
        <form action='.' method='post' name="Fusers">
            <table>
                <tr>
                    <td>Last name: </td>
                    <td><input type='text' tabindex='1' id="last_name" name='last_name' value='{{ search.last_name }}'></td>
                </tr><tr>
                    <td>First name: </td>
                    <td><input type='text' tabindex='2' id="first_name" name='first_name' value='{{ search.first_name }}'></td>
                </tr><tr>
                    <td>Username: </td>
                    <td><input type='text' tabindex='3' id="username" name='username' value='{{ search.username }}'></td>
                </tr><tr>
                    <td>Email: </td>
                    <td><input type='text' tabindex='4' id="email" name='email' value='{{ search.email }}'></td>
                </tr><tr>
                </tr><tr>
                    <td>Building:</td>
                    <td>
                        <select name="building" tabindex='5' >
                            {% for building in buildings %}
                                <option value={{ building.id }} {% if building.selected %} selected='selected' {% endif %} >
                                    {{ building.name }}
                                </option>
                            {% endfor %}
                        </select>
                    </td>
                    <td>
                      {% if user.userprofile.building %}
                        <input type="checkbox" id="from_my_building" name="from_my_building" value="checked" tabindex="6" {% if from_my_building %} checked="checked" {% endif %} >
                        <label for="from_my_building">From my building</label>
                      {% endif %}
                    </td>
                </tr><tr>
                    <!-- <td></td> -->
                    <td> </td>
                    <td>
                        <input type='submit'  name='search' value='Search' tabindex='7' accesskey="s" >
                    </td>
                </tr>
            </table>
        </form>

        <script type="text/javascript">
            document.Fusers.last_name.focus();
        </script>
      </center>
    </div>

    {% if perms.auth.add_user %}
    <div class="add_new_user">
      <a href="/entelib/users/add/">Add new user</a>
    </div>
    {% endif %}

    {% if rows|length %}
      <div class="found_count">
        <p>Found {{rows|length}} user{{rows|length|pluralize}}</p>
      </div>
    {% endif %}
{% endblock before_table %}

{% block header_row %}
  {% if not non_found %}
    {% block header_row_start %}
    {% endblock header_row_start %}
    <th>Username</th>
    <th>First name, last name</th>
    <th>Email</th>

    {% comment %}
      <th>Is librarian</th>
      <th>Is admin</th>
    {% endcomment %}

    {% block header_row_end %}
    {% endblock header_row_end %}
  {% endif %}
{% endblock header_row %}


{% block item_row %}
        {% block row_start %}
        {% endblock row_start %}
        <td>
            <a href="{{ row.id }}">{{ row.username }}</a>
        </td> <td>
            <a href="{{  row.id }}">{{ row.first_name }} {{ row.last_name }}</a>
        </td> <td>
            <a href='mailto:{{row.email}}'>{{ row.email }}</a>


        {% comment %}
        </td> <td>
            {{ row.userprofile.is_librarian|yesno:_("Yes,No") }}
         </td> <td>
            {{ row.userprofile.is_admin|yesno:_("Yes,No") }}
        {% endcomment %}
        </td>
        {% block row_end %}
        {% endblock row_end %}
{% endblock item_row %}


{% block after_table %}
    {% if non_found %}
        <p><b>No users found.</b></p>
    {% else %}
        {% go_back_link %}
    {% endif %}
{% endblock %}
